var AjaxCrud = QualityCheck.AjaxCRUD;
var serverUrl = QualityCheck.GPUD.ServiceConfig;
//学生搜索年级班级联动
function studentSeachMenu(){
	var classes = $(".classes-choice",parent.document);
	var content = "";
	for(var i = 0; i < classes.length; i++){
		content += "<option value='"+classes[i].getAttribute("classcode")+"'>"+classes[i].innerHTML+"</option>";
	}
	$("#student-grade",parent.parent.document).empty();
	$("#student-grade",parent.parent.document).append(content);
	initStudents(1,10000);
	
	$("#student-grade",parent.parent.document).unbind("change");
	$("#student-grade",parent.parent.document).change(function(){
		initStudents(1,10000);
	});
}
function initStudents(currentpage,pagesize){
	$(".loading",parent.parent.document).show();
	var userKey = $("#user-name",parent.parent.document).attr("key");	
	var schoolcode = $("#user-name",parent.parent.document).attr("schoolcode");
	var name = $("#student-choice-name",parent.parent.document).val();
	var classcode = $("#student-grade option:selected",parent.parent.document).val();
	var islock = "1";
	var data = {
			cmd:"getAllStudentsByPage",
			model:"student",
			userKey:userKey,
			data:{
				currentpage:currentpage,
				pagesize:pagesize,
				name:encodeURI(name),
				classcode:classcode,
				del:islock,
				schoolcode:schoolcode
			},
			remark:"",
	};
	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(res){
		$(".loading",parent.parent.document).hide();
		var content = "";
		if(res.result == 1 && res.data != undefined && res.data != ""){
			var list = res.data.data;
			if(list.length > 0){
				for(var i = 0; i < list.length; i ++){
					content += "<option value='"+ list[i].name +"' studentcode='" + list[i].studentcode +"' title='" + list[i].name + "' imei='" + list[i].imei +"'>" + list[i].name + "</option>";
				}
			}else{
				content += "<option style='text-align:center;' disabled='disabled'>未查询到学生！</option>";				
				$("#selectR",parent.parent.document).empty();
			}
			$("#selectL",parent.parent.document).empty();
			$("#selectL",parent.parent.document).append(content);
			selSelectedData();
		}else{
			var content = "<option style='text-align:center;' disabled='disabled'>未查询到学生！</option>";
			$("#selectL",parent.parent.document).empty();
			$("#selectL",parent.parent.document).append(content);
			$("#selectR",parent.parent.document).empty();			
		}
	});
}
function selectLR(){
	var leftSel = $("#selectL",parent.parent.document);
	var rightSel = $("#selectR",parent.parent.document);
	$("#toright",parent.parent.document).bind("click",function(){		
		leftSel.find("option:selected",parent.parent.document).each(function(){
			$(this).remove().appendTo(rightSel);
		});
	});
	$("#toleft",parent.parent.document).bind("click",function(){		
		rightSel.find("option:selected",parent.parent.document).each(function(){
			$(this).remove().appendTo(leftSel);
		});
	});
	leftSel.dblclick(function(){
		$(this).find("option:selected",parent.parent.document).each(function(){
			$(this).remove().appendTo(rightSel);
		});
	});
	rightSel.dblclick(function(){
		$(this).find("option:selected",parent.parent.document).each(function(){
			$(this).remove().appendTo(leftSel);
		});
	});
};
function selSelectedData(){
	var leftSel = $("#selectL option",parent.parent.document);
	var rightSel = $("#selectR",parent.parent.document);
	var studentcodes = $("#anotices-students").attr("studentcodes").split(",");
	rightSel.empty();
	if(studentcodes.length > 0){
		for(var i = 0; i < studentcodes.length; i ++){
			leftSel.each(function(){
				if($(this).attr("studentcode") == studentcodes[i]){
					$(this).remove().appendTo(rightSel);
				}
			});
		}
	}
	rightSel.find("option").attr("selected",true);
}
